package Problem04;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Desktop {
    public static boolean login(String password){
        if(password.equals("123456")){
           return true;

        }
        else{
            return false;
        }
    }
public static List <Student> list=new ArrayList<Student>();
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("欢迎来到学生管理系统");
        System.out.println("请输入您的密码");
        String password=sc.next();
        if(login(password)){
            while (true){
                System.out.println("请选择您要进行的操作按键");
                System.out.println("录入学生信息请按【1】");
                System.out.println("删除学生信息请按【2】");
                System.out.println("修改学生信息请按【3】");
                System.out.println("显示全部学生信息请按【4】");
                System.out.println("结束操作并退出请按【0】");
                int command =sc.nextInt();
                if(command==0){
                    break;
                }
                switch (command){
                    case 1:String resultofadd=add();
                        System.out.println(resultofadd);
                    continue;
                    case 2:String resultofdelete=delete();
                        System.out.println(resultofdelete);
                    continue;
                    case 3:String resultofrenew=renew();
                        System.out.println(resultofrenew);
                    continue;
                    case 4:show();

                }

            }
        }
        else{
            System.out.println("您输入的密码错误，请检查后重新登陆");
        }

    }
    public static String add(){
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入学生学号：");
        int tempnumber=sc.nextInt();
        System.out.println("请输入学生年龄：");
        int tempage=sc.nextInt();
        System.out.println("请输入学生姓名：");
        String tempname=sc.next();
        Student stu=new Student(tempage,tempname,tempnumber);
        list.add(stu);
        return "添加成功";
    }
    public static String delete(){
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入要删除的学生学号");
        int deletednumber=sc.nextInt();
        for(int i=0;i<list.size();i++){
            if(deletednumber==list.get(i).getNumber()){
                list.remove(i);
                return "删除成功";
            }
        }
        return "未发现您要删除的学生信息，删除失败";
       

    }
    public static String renew(){
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入您要更改的学生学号：");
        int changednumber=sc.nextInt();
        for (Student student : list) {
            if (changednumber == student.getNumber()) {
                System.out.println("请输入您要更改的学生信息类型");
                System.out.println("1.姓名    2.年龄     3.学号");
                int choice = sc.nextInt();
                switch (choice) {
                    case 1:
                        System.out.println("请输入新的学生姓名");
                        String changedname = sc.next();
                        student.setName(changedname);
                        break;
                    case 2:
                        System.out.println("请输入新的学生年龄");
                        int changedage = sc.nextInt();
                        student.setAge(changedage);
                        break;
                    case 3:
                        System.out.println("请输入新的学号");
                        int newnumber = sc.nextInt();
                        student.setNumber(newnumber);
                        break;

                }
                return "更改成功";
            }
        }
        return"未找到您要更改的部分，更改失败";
    }
    public static void show(){
        for (Student s2:list
             ) {
            System.out.println("学号："+s2.getNumber()+"  姓名："+s2.getName()+"  年龄："+s2.getAge());
        }

    }
}
